package org.metasketch.demo.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.metasketch.model.CommonIdentified;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("transaction-step")
public class TransactionStep extends CommonIdentified {

	// String id;
	@XStreamAsAttribute
	@XStreamAlias("parent-transaction")
	TransactionKind parentTransaction;

	ActionRule rule;

	@XStreamAlias("owned-coordination-links")
	Set<CoordinationLink> ownedCoordinationLinks = new HashSet<CoordinationLink>();

	@XStreamAsAttribute
	@XStreamAlias("actor-role")
	ActorRole actorRole;

	// public String getId() {
	// return id;
	// }
	//
	// public void setId(String id) {
	// this.id = id;
	// }

	public CoordinationLink getFirstLinkTo(TransactionStep step) {
		for (CoordinationLink link : ownedCoordinationLinks) {
			if (link.getTarget() == step)
				return link;
		}
		return null;
	}

	public TransactionKind getParentTransaction() {
		return parentTransaction;
	}

	public void setParentTransaction(TransactionKind parent) {
		this.parentTransaction = parent;
	}

	public ActionRule getRule() {
		return rule;
	}

	public void setRule(ActionRule rule) {
		this.rule = rule;
	}

	public Set<CoordinationLink> getOwnedCoordinationLinks() {
		return ownedCoordinationLinks;
	}

	public void setOwnedCoordinationLinks(Set<CoordinationLink> links) {
		this.ownedCoordinationLinks = links;
	}

	public ActorRole getActorRole() {
		return actorRole;
	}

	public void setActorRole(ActorRole actorRole) {
		this.actorRole = actorRole;
	}

}
